package com.sfang.common.util.dingTalk;

import com.alibaba.fastjson.JSONObject;
import com.sfang.common.base.entity.RestInfo;
import com.sfang.common.util.http.HttpClientUtils;

import java.util.HashMap;
import java.util.Map;

public class DingTalkUtil {
    public static RestInfo send(String content, String robotUrl) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msgtype", "text");

        JSONObject contentJson = new JSONObject();
        contentJson.put("content", content);

        JSONObject ajJson = new JSONObject();
        ajJson.put("atMobiles", null);
        ajJson.put("isAtAll", false);

        jsonObject.put("text", contentJson.toJSONString());
        jsonObject.put("at", ajJson.toJSONString());

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");

        RestInfo restInfo = HttpClientUtils.sendPostJSON(robotUrl, jsonObject.toJSONString(), headers);
        return restInfo;

    }
}
